package com.ordertracker.entity;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * Description of class.
 * Created 1/18/13 4:50 PM
 *
 * @author andrey.rodin@playtech.com
 */

@XmlRootElement
public class Employee extends VersionedEntity {
    private static final long serialVersionUID = -5467432081597580204L;

    private String name;
    private int code;
    private Role role;
    private User user;
    private Organization organization;
    private Position position;

    public Employee() {
    }

    public Employee(String name, int code, Role role, User user, Organization organization, Position position) {
        this.name = name;
        this.code = code;
        this.role = role;
        this.user = user;
        this.organization = organization;
        this.position = position;
    }

    @XmlElement(nillable = false)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @XmlElement
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    @XmlElement(nillable = false)
    public Role getRole() {
        return role;
    }

    public void setRole(Role role) {
        this.role = role;
    }

    @XmlElement(nillable = false)
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @XmlElement(nillable = false)
    public Organization getOrganization() {
        return organization;
    }

    public void setOrganization(Organization organization) {
        this.organization = organization;
    }

    @XmlElement(nillable = false)
    public Position getPosition() {
        return position;
    }

    public void setPosition(Position position) {
        this.position = position;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Employee)) return false;
        if (!super.equals(o)) return false;

        Employee employee = (Employee) o;

        if (code != employee.code) return false;
        if (!name.equals(employee.name)) return false;
        if (!organization.equals(employee.organization)) return false;
        if (!role.equals(employee.role)) return false;
        if (!user.equals(employee.user)) return false;
        if (!position.equals(employee.position)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = 31 * result + name.hashCode();
        result = 31 * result + code;
        result = 31 * result + role.hashCode();
        result = 31 * result + user.hashCode();
        result = 31 * result + organization.hashCode();
        result = 31 * result + position.hashCode();
        return result;
    }

    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                ", code=" + code +
                ", role=" + role.getName() +
                ", user=" + user.getName() +
                ", organization=" + organization.getShortName() +
                ", position=" + position.getName() +
                ", " + super.toString();
    }
}
